<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">

        <div class="fieldset1 clearFix">
            <div class="fieldBox" >
                <div class="label">公告型号</div>
                <div class="field">
                    <input name="styleBulletinModel" id="styleBulletinModel" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">车型ID</div>
                <div class="field">
                    <input name="styleId" id="styleId" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">发动机</div>
                <div class="field">
                    <input name="styleEngine" id="styleEngine" type="text"   class="ui-textbox" value="">
                </div>
            </div>
              <div class="fieldBox" >
                <div class="label">品牌</div>
                <div class="field">
                  <input name="brCd" id="brCd" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">车系</div>
                <div class="field">
                    <input name="carModel" id="carModel" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox"  >
                <div class="label"> 车辆用途：</div>
                <div class="field">
                    <%--<input name="carUsageLv1" id="carUsageLv1" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">--%>
                    <input name="carUsage" id="carUsage" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox"   >
                <div class="label"> 车型：</div>
                  <div class="field">
                      <input name="carStyle" id="carStyle" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                  </div>
            </div>


            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
              <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
             <span id="detailBtn" class="sq-button sq-button-round" onclick="detailBtn()">确定</span>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null;
    var prjId= '${prjId}';
    var brandComboBox = null;
    var carModelComboBox = null ;
    var carStyleComboBox = null ;
    var carUsageComboBoxLv1 = null;
    var carUsageComboBoxLv2 = null;
    $(function () {
        // 初始化品牌下拉
        initBrand();
        brandComboBox = liger.get("brCd");
        prdGrid();
        initCarModel();
        carModelComboBox = liger.get("carModel");
        carModelComboBox.setDisabled(true)
        initCarStyle(180322537000001);
        carStyleComboBox = liger.get("carStyle");
        carStyleComboBox.setDisabled(true);
        initCarUsageLv2();
        carUsageComboBoxLv2 = liger.get("carUsage");
        carUsageComboBoxLv2.setDisabled(true);
    });

    /**
     * 初始化品牌下拉信息
     */
    function initBrand(){
        $("#brCd").ligerComboBox({
            url: '<%=path%>/project/vehicle/brand.do',
            ajaxType: "get",
            parms:{str:"1"},
            width: 120,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {

                // 重新加载车系
                initCarModel();
                if(carModelComboBox){
                    carModelComboBox.setValue("")
                    carModelComboBox.setEnabled(true);
                }
                // 清空车型选择
                if(carStyleComboBox){
                    carStyleComboBox.setValue("");
                    carStyleComboBox.setDisabled(true);
                }
                //清空用途
               if(carUsageComboBoxLv2){
                   carUsageComboBoxLv2.setValue("");
                   carUsageComboBoxLv2.setDisabled(true);
               }

            }
        });
    }

    /**
     *  初始化车系下拉
     *  必须选择了品牌才会真正加载内容
     */
    function initCarModel(){
        var url = null;
        var brandId = null ;
        if(brandComboBox){
            if(brandComboBox.getValue()){
                url = '<%=path%>/project/vehicle/carModel.do'
                brandId = brandComboBox.getValue();
            }
        }
        $("#carModel").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{brandId:brandId},
            width: 120,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                //重载用途2级
                initCarUsageLv2();
                if(carUsageComboBoxLv2){
                    carUsageComboBoxLv2.setEnabled(true);
                    carUsageComboBoxLv2.setValue("");
                }

                // 清空车型
                if(carStyleComboBox){
                    carStyleComboBox.setDisabled(true);
                    carStyleComboBox.setValue("");
                }


            }
        });
    }
    /**
     * 初始化车型下拉
     * 必须选择了车系才会加载
     */
    function initCarStyle(brandId){
        var url = null;
        var brandId = null;
        var carModelId = null;
        var purpose = null ;
        if(carModelComboBox){
            if(carModelComboBox.getValue()){
                url = '<%=path%>/project/vehicle/carStyle.do'
                brandId = brandComboBox.getValue();
                carModelId = carModelComboBox.getValue();
                purpose = carUsageComboBoxLv2.getValue();
            }
        }
        $("#carStyle").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{brandId:brandId,carModelId:carModelId,purpose:purpose},
            width: 430,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
            }
        });
    }
    /**
     * 初始化车辆用途一级类
     * 必须选择了车型才会加载
     */
    function initCarUsageLv1(){
        var url = null;
        var modelId = null;
        if(carModelComboBox){
            if(carModelComboBox.getValue()){
                modelId = getComboBoxValue(carModelComboBox);
                url = '<%=path%>/project/vehicle/carUsageLv1.do'
            }
        }

        $("#carUsageLv1").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{modelId:modelId},
            width: 140,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                // 打开车辆用途
                initCarUsageLv2();
                carUsageComboBoxLv2.setEnabled(true);
                carUsageComboBoxLv2.setValue("");

                if(carStyleComboBox){
                    carStyleComboBox.setDisabled(true);
                    carStyleComboBox.setValue("");
                }
            }
        });
    }
    /**
     * 初始化车辆用途LV2
     * 必须选择了车型才会加载
     */
    function initCarUsageLv2(){
        var url = null;
        var modelId = null;
        if(carModelComboBox){
            if(carModelComboBox.getValue()){
                modelId = carModelComboBox.getValue();
                url = '<%=path%>/project/vehicle/carUsage.do'
            }
        }
        var lv1 = null;
        if(carUsageComboBoxLv1){
            lv1 = carUsageComboBoxLv1.getValue();
        }
        $("#carUsage").ligerComboBox({
            url: url,
            ajaxType: "get",
            parms:{lv1:lv1,modelId:modelId},
            width: 140,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
                // 清空车型
                initCarStyle();
                if(carStyleComboBox){
                    carStyleComboBox.setEnabled(true);
                    carStyleComboBox.setValue("");
                }
            }
        });
    }

    /**
     * 获取comboBox的值
     * @param comboBox
     * @returns {null}
     */
    function getComboBoxValue(comboBox){
        if(comboBox){
            var selected = comboBox.getValue();
            if(selected){
                return selected;
            }
        }
        return null;
    }
    //根据产品类型加载不同的grid
    function prdGrid(prdType,parms){
        // 品牌id
        var brandId = getComboBoxValue(brandComboBox);
        // 车系id
        var modelId = getComboBoxValue(carModelComboBox);
        // 车型id
        var styleId = getComboBoxValue(carStyleComboBox);
        // 用途id
        var usageId =  getComboBoxValue(carUsageComboBoxLv2);
        // 公告型号
        var styleBulletinModel = $("#styleBulletinModel").val();
        var styleEngine = $("#styleEngine").val();
        // 车型ID
        var styleId2 = $("#styleId").val();
        if(StringUtils.isNotEmpty(styleId2)){
            styleId = styleId2;
        }

        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/project/vehicle/initList.do',
            method : 'get',
            parms : {makeId:brandId,modelid:modelId,id:styleId,stylePurposeId:usageId,styleBulletinModel:styleBulletinModel,styleEngine:styleEngine},
            columns: [
                { display: '车型名称', name: 'styleName', minWidth: 150 ,
                    enabledSort:true},
                { display: '品牌', name: 'makeName', minWidth: 150 ,
                    enabledSort:true},
                { display: '车型ID', name: 'id', minWidth: 150 ,
                    enabledSort:true},
                { display: '产品名称', name: 'stylePurposeName', minWidth: 150 ,
                    enabledSort:true},
                { display: '参考价', name: 'styleMsrp', width: 100,
                    render: function (rowdata, rowindex, value, column) {
                        if(value){
                            var h = value + "万元";
                            return h;
                        }
                    },
                    enabledSort:true},
                { display: '发动机型号', name: 'styleEngine', minWidth: 140 , enabledSort:true},

                // { display: '产品类型', name: 'stylePurposeId', minWidth: 150 , enabledSort:true},
                { display: '驱动形式', name: 'styleDriveMode', minWidth: 100 , enabledSort:true},
                { display: '排量', name: 'styleEmission', minWidth: 100 , enabledSort:true},
                { display: '最大马力', name: 'engineMaxHorsepower', minWidth: 100 , enabledSort:true},
                { display: '货箱内部尺寸', name: '_0', minWidth: 140 , enabledSort:true,render:function(rowData){
                    // 全是空就 显示"无"
                        if(!rowData.containerLength && !rowData.containerWidth && !rowData.containerHeight){
                            return "无"
                        }
                        var length = "空";
                        if(rowData.containerLength){
                            length = rowData.containerLength;
                        }
                        var width="空";
                        if(rowData.containerWidth){
                            width = rowData.containerWidth;
                        }
                        var height = "空";
                        if(rowData.containerHeight){
                            height = rowData.containerHeight;
                        }
                        return length + "*" + width + "*" + height;
                }},
                { display: '轮胎规格', name: 'tyreTyresize', minWidth: 140 , enabledSort:true},
                { display: '轴距', name: 'styleWheelbase', minWidth: 140 , enabledSort:true},
                { display: '搅拌容积', name: 'xxx', minWidth: 140 , enabledSort:true},
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            //isScroll: false,
            checkbox:true,
            rownumbers:true
        });
        grid = liger.get("ligergrid1");
    }

    function searchBtn(){
        // TODO
        var selected = brandComboBox.getValue();
        var selected2 = carModelComboBox.getValue();
        if(selected){ //如果选了品牌 必须选车系
            if(!selected2){
                alert("请选择车系")
                return;
            }
        }
                       prdGrid();
    }
    
    function detailBtn(){
        var prdCd = null;
        var bizTypCd = null;
        var bizCd = null;
        var sGrpCd = null;
        var sCode = null;
        var prdTypCdNm = null
        
        // if(searchPrdTypeTree.treeManager.getSelected()){
         // //      prdCd = searchPrdTypeTree.treeManager.getSelected().data['id'];
         //     bizTypCd = searchPrdTypeTree.treeManager.getSelected().data['tGrpCd'];//目标代码组值
         //     bizCd = searchPrdTypeTree.treeManager.getSelected().data['tCode'];//目标代码值
         //     sGrpCd = searchPrdTypeTree.treeManager.getSelected().data['sGrpCd'];//源代码组值
            // sCode = searchPrdTypeTree.treeManager.getSelected().data['sCode'];//源代码值
         //     prdTypCdNm =searchPrdTypeTree.treeManager.getSelected().data['tName'];//目标代码名
        // }
        
        //alert(bizTypCd+"---"+bizCd+"---"+sGrpCd+"---"+sCode+"---"+prdTypCdNm);
        var selectedRows = grid.getSelectedRows();
        if(selectedRows.length != 1){
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        }

        
        var callback = frameElement.dialog.get("callback");
        var id = selectedRows[0].id;
        var purposeCd = selectedRows[0].stylePurposeId;
        //var prdTypCd= selectedRows[0].prdTypCd;
        //var prdCd = selectedRows[0].prdBscInfoVO.prdCd;
        var prjPrdChangeFlag= '${prjPrdChangeFlag}';
        var oldDtlId= '${oldDtlId}';
        var paySchId= '${paySchId}';
        var paySchNo= '${paySchNo}';
        if (prjPrdChangeFlag && prjPrdChangeFlag == 'true') {
            parent.Add_navTab('tab_project_prd_detail' + id, '项目产品详细信息', '<%=path%>/project/vehicle/toPrjPrdDetailPageByHC.do?id=' + id + '&&prjId=' + prjId + '&&purposeCd=' + purposeCd + '&&prjPrdChangeFlag=' + prjPrdChangeFlag
                + '&&oldDtlId=' + oldDtlId + '&&paySchId=' + paySchId + '&&paySchNo=' + paySchNo, callback);
        } else {
            parent.Add_navTab('tab_project_prd_detail'+id,'项目产品详细信息','<%=path%>/project/vehicle/toPrjPrdDetailPage.do?id='+id+'&&prjId='+prjId + '&&purposeCd='+purposeCd,callback);
        }
        parent.$.ligerDialog.close();
        parent.$(".l-dialog,.l-window-mask").css("display","none"); 
    }
    
    function clearBtn(){
        brandComboBox.setValue("");
        carModelComboBox.setValue("")
        carModelComboBox.setDisabled(true);
        carStyleComboBox.setValue("")
        carStyleComboBox.setDisabled(true);
        carUsageComboBoxLv2.setValue("")
        $("#styleId").val("");

        // carUsageComboBoxLv1.setValue("")
        $("#styleBulletinModel").val("");
    }
    
    function iframeResize () {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        };
    }
    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }


</script>

</body>
</html>